package com.kadron.size;

import java.io.Serializable;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;

import com.kadron.common.KConst;
import com.kadron.dao.KSizeDAO;
import com.kadron.entity.Size;
import com.kadron.manager.KMessageManager;

@AutoCreate
@Name("kSizeManager")
@Scope(ScopeType.PAGE)
public class KSizeManager extends KMessageManager implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4184026689307942094L;

	private static final Log log = LogFactory.getLog(KSizeManager.class);
	
	private Size size; 
	
	@In
	private KSizeDAO sizeDAO;
	
	@Create
	public void init() {
		Long sizeId = (Long) Component.getInstance("sizeId");
		if (sizeId == null) {
			sizeId = new Long(0);
		}
		if (sizeId > 0) {
			size = (Size) sizeDAO.find(sizeId, Size.class);
		} else {
			size = new Size();
		}
	}
	
	public String save() {
		if (size == null) {
			bad(KConst.BAD_THING);
			return null;
		}
		if (log.isDebugEnabled()) {
			log.debug("Save Size sizeId="+size.getId());
		}
		sizeDAO.update(size);
		good();
		return "size";
	}

	public Size getSize() {
		return size;
	}

	public void setSize(Size size) {
		this.size = size;
	}
}
